package util
{
	import mx.collections.ArrayCollection;
	import mx.collections.ArrayList;

	public class CommonOp
	{
		public function CommonOp()
		{
		}
		public static function GetBaseUrl(swfUrl:String):String
		{
			var pos1:int = swfUrl.lastIndexOf("/");
			var urlParent:String = swfUrl.substr(0,pos1);
			var pos2:int= urlParent.lastIndexOf("/");
			var urlRealParent:String = urlParent.substr(0,pos2);
			return urlRealParent;
		}
		
		public static function fillData(table:Object,targetArray:ArrayCollection):void
		{
			targetArray.removeAll();
			if(table!=null){
				var datas:Array = table.serverInfo.initialData;
				var cols:Array = table.serverInfo.columnNames;
				for (var i:int=0; i<datas.length; i++)
				{
					var obj:Object = new Object();
					for (var j:int =0; j<cols.length; j++)
					{
						obj[cols[j]] = datas[i][j];
					}
					targetArray.addItem(obj);
				}
			}
		}

		/*
		通过名称来获取相应的下拉列表索引
		*/
		public static function getIndexByName(list:ArrayList, key:String):int
		{ 
			var index:int = 0; 
			for(var i:int = 0; i<list.length; i++){ 
				var obj:Object = list.source[i];
				if(obj.Name == key){ 
					index = i;
					break; 
				} 
			}
			return index; 
		}
		
		public static function getIndexByID(list:ArrayList, key:String):int
		{ 
			var index:int = 0; 
			for(var i:int = 0; i<list.length; i++){ 
				var obj:Object = list.source[i];
				if(obj.ID == key){ 
					index = i;
					break; 
				} 
			}
			return index; 
		}
		public static  function getIDByName(list:*,name:String):String{
			for each(var obj:Object in list){
				if(obj.Name==name){
					return obj.ID;
				}
			}
			return "";
		}
		
	}
}